import { defineStore } from 'pinia'
// 操作仓库

export const useOperate = defineStore(
  'operate',
  () => {
    const visible = ref<Boolean>(false)
    const type = ref<Number | String>(1)
    const name = ref<String>('')
    const typeObj = ref<Object>({})
    const form = ref<any>({})

    // 更改dialog显影
    const setVisible = (value: Boolean) => {
      visible.value = value
    }
    // 更改当前表单类型 1:新增 2:编辑 3:删除
    const setType = (value: Number) => {
      type.value = value
    }
    // 更改当前form表单数据
    const setName = (value: String) => {
      name.value = value
    }
    // 更改当前表单类型 1:新增 2:编辑 3:删除
    const setTypeObj = (value: Object) => {
      typeObj.value = value
    }
    // 更改当前form表单数据
    const setForm = (value: any) => {
      form.value = value
    }

    return {
      visible,
      type,
      name,
      typeObj,
      form,
      setVisible,
      setType,
      setName,
      setTypeObj,
      setForm
    }
  },
  {
    // 开启数据持久化缓存
    persist: {
      enabled: true, // 是否开启pinia数据持久化
      strategies: [
        {
          storage: sessionStorage //表示存储在localStorage
        }
      ]
    }
  }
)
